
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AutoUpdate.DAL;
using AutoUpdate.Models;
using System.Data.SqlClient;

namespace AutoUpdate.BLL
{
    [Serializable]
    public static class T_SysUpdateManager
    {
        /// 分页查询
        /// </summary>
        /// <param name="count">总页数</param>
        /// <param name="ji">要访问的页码</param>
        /// <param name="size">一页显示多少数据</param>
        /// <returns>要显示页的数据</returns>
        /// <exception cref="有异常抛出">有异常抛出</exception>
        public static List<AutoUpdate.Models.T_SysUpdate> GetStudentFen(out int count,int ye = 1,int size=10)
        {
            try
            {
                return T_SysUpdateService.GetByFenYe(out count,ye,size);
            }
            catch
            {

                throw;
            }
        }
        /// <summary>
        /// 判断是否存在
        /// </summary>
        /// <returns> true or false</returns>
        /// <exception cref="有异常抛出">有异常抛出</exception>
        public static bool IsExitsHas(string id)
        {
            string where = " and ID = @id";

            SqlParameter[] paras =
            {
                new SqlParameter("@id",id)
            };
            try
            {
                return T_SysUpdateService.GetAllList(where,paras).Count == 1;
            }
            catch
            {
                throw;
            }
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="grade"></param>
        /// <returns>是否添加成功</returns>
        /// <exception cref="有异常抛出">有异常抛出</exception>
        public static bool Add(AutoUpdate.Models.T_SysUpdate result)
        {
            //判断是否存在
            if (IsExitsHas(result.ID.ToString()))
                return false;
            try
            {
                return T_SysUpdateService.Add(result) == 1;
            }
            catch
            {
                throw;
            }
        }
        /// <summary>
        /// 根据id获取内容
        /// </summary>
        /// <returns>获取到的内容</returns>
        /// <exception cref="有异常抛出">有异常抛出</exception>
        public static List<AutoUpdate.Models.T_SysUpdate> GetT_SysUpdateReader(string ID)
        {
            List<AutoUpdate.Models.T_SysUpdate> list = null;
            try
            {
                string where = " and ID = @ID";
                SqlParameter[] paras =
                {
                    new SqlParameter("@ID",ID)
                };
                list = T_SysUpdateService.GetAllList(where, paras);
                return list;
            }
            catch
            {
                throw;
            }
        }
        /// <summary>
        /// 获取所有
        /// </summary>
        /// <returns>获取到的list集合</returns>
        /// <exception cref="有异常抛出">有异常抛出</exception>
        public static List<AutoUpdate.Models.T_SysUpdate> getAllT_SysUpdate()
        {
            List<AutoUpdate.Models.T_SysUpdate> list = null;
            try
            {
                list = T_SysUpdateService.GetAllList();
                return list;
            }
            catch
            {
                throw;
            }
        }
        /// <summary>
        /// 根据对象删除
        /// </summary>
        /// <param name="result">要删除的对象</param>
        /// <returns>是否删除成功</returns>
        /// <exception cref="有异常抛出">有异常抛出</exception>
        public static bool Delete(AutoUpdate.Models.T_SysUpdate result)
        {
            try
            {
                return T_SysUpdateService.Delete(result.ID) == 1;
            }
            catch
            {
                throw;
            }
        }
        /// <summary>
        /// 按主键进行删除
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>是否删除成功</returns>
        /// <exception cref="有异常抛出">有异常抛出</exception>
        public static bool Delete(string id)
            {
                try
                {
                    return T_SysUpdateService.Delete(id) == 1;
                }
                catch
                {
                    throw;
                }
            }
        /// <summary>
        /// 根据主键删除多个
        /// </summary>
        /// <param name="results">要删除主键的数组</param>
        /// <returns>删除的数量</returns>
        /// <exception cref="有异常抛出">有异常抛出</exception>
        public static int Delete(string[] results)
        {
            StringBuilder sb = new StringBuilder("0");
            foreach (string id in results)
            {
                sb.Append("," + id);
            }
            string where = " and ID in (" + sb + ")";
            try
            {
                return T_SysUpdateService.Delete(where);
            }
            catch
            {
                throw;
            }
        }
        
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="result">修改后的对象</param>
        /// <returns>受影响行数</returns>
        /// <exception cref="有异常抛出">有异常抛出</exception>
        public static int Update(AutoUpdate.Models.T_SysUpdate result)
        {
            try
            {
                int r = T_SysUpdateService.Update(result);
                return r;
            }
            catch
            {
                throw;
            }
        }
    }
}

